﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TheSnakeGame.Engine.GameObjects;
using TheSnakeGame.Engine;
using System.ComponentModel;

namespace TheSnakeGame.WpfClient.DrawableObjects
{
    public class DrawableObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public DrawableObject(GameObject underlyingObject)
        {
            this.Width = 10;
            this.Height = 10;
            this.UnderlyingObject = underlyingObject;
            this.UnderlyingObject.Position.PropertyChanged += Position_PropertyChanged;
        }

        void Position_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var propertyChangedName = e.PropertyName;
            if (propertyChangedName == "X")
            {
                this.OnPropertyChanged("Left");
            }
            if (propertyChangedName == "Y")
            {
                this.OnPropertyChanged("Top");
            }
        }

        public int Width
        {
            get;
            set;
        }

        public int Height
        {
            get;
            set;
        }

        public int Top
        {
            get
            {
                return this.UnderlyingObject.Position.Y * this.Height;
            }
        }

        public int Left
        {
            get
            {
                return this.UnderlyingObject.Position.X * this.Width;
            }
        }

        public GameObject UnderlyingObject
        {
            get;
            set;
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
